package org.zn.etl.datasource;

import java.util.Map;

import javax.sql.DataSource;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component("SpringDataSourceFactory")
public class SpringDataSourceFactory  extends DataSourceFactory implements ApplicationContextAware{

	private	ApplicationContext applicationContext;
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		// TODO Auto-generated method stub
		this.applicationContext=applicationContext;
	}
	
	 public DataSource getDataSource(String  keyName,Map<String, String> dataSourceConfig) {
		 
		 Map<String, DataSource>   dsMap= applicationContext.getBeansOfType(DataSource.class);
		 
		 return dsMap.get(keyName);
		 
	 }
	 
	 public DataSource getDataSource(String  keyName) {
		 
		 Map<String, DataSource>   dsMap= applicationContext.getBeansOfType(DataSource.class);
		 
		 return dsMap.get(keyName);
		 
	 }

}
